home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Convert_VB339301182001.psc / ODL Converter / Classes / Basic Lang.cls next >
Encoding:
Visual Basic class definition  |  2001-11-07  |  27.9 KB  |  756 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "BasicLanguage"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = False
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. Implements SCLangEngine
  16. Private m_colKeyWords As Collection
  17. Private m_colOperators As Collection
  18. Private r_gslLanguage As SCLanguage
  19.  
  20. Private Function SCLangEngine_StandardParse(ByVal Expression As String) As SemanticResult
  21.     SCLangEngine_StandardParse = SemanticParse(LexicalParse(Expression))
  22. End Function
  23.  
  24. Private Function SCLangEngine_SemanticParse(LexicalInput As LexicalResult) As SemanticResult
  25.     SCLangEngine_SemanticParse = SemanticParse(LexicalInput)
  26. End Function
  27.  
  28. Private Function SCLangEngine_LexicalParse(ByVal Expression As String) As LexicalResult
  29.     SCLangEngine_LexicalParse = LexicalParse(Expression)
  30. End Function
  31.  
  32. Private Property Get SCLangEngine_Language() As SCLanguage
  33.     Set SCLangEngine_Language = r_gslLanguage
  34. End Property
  35.  
  36. Private Property Set SCLangEngine_Language(ByVal v_gslLanguage As SCLanguage)
  37.     Set r_gslLanguage = v_gslLanguage
  38.     If Not v_gslLanguage Is Nothing Then
  39.         With v_gslLanguage
  40.             .AddKeyWord m_gl_CST_strKwdAlias, m_gl_CST_strKwdAlias
  41.             .AddKeyWord "Open", "Open"
  42.             .AddKeyWord "Close", "Close"
  43.             .AddKeyWord "Exit", "Exit"
  44.             .AddKeyWord "Output", "Output"
  45.             .AddKeyWord "Debug", "Debug"
  46.             .AddKeyWord "Print", "Print"
  47.             .AddKeyWord "Binary", "Binary"
  48.             .AddKeyWord "Random", "Random"
  49.             .AddKeyWord "Access", "Access"
  50.             .AddKeyWord "Implements", "Implements"
  51.             .AddKeyWord "If", "If"
  52.             .AddKeyWord "ElseIf", "ElseIf"
  53.             .AddKeyWord "#End", "#End"
  54.             .AddKeyWord "#ElseIf", "#ElseIf"
  55.             .AddKeyWord "#Else", "#Else"
  56.             .AddKeyWord "Else", "Else"
  57.             .AddKeyWord "Then", "Then"
  58.             .AddKeyWord "Not", "Not"
  59.             .AddKeyWord "Preserve", "Preserve"
  60.             .AddKeyWord "Redim", "Redim"
  61.             .AddKeyWord "Goto", "Goto"
  62.             .AddKeyWord "Resume", "Resume"
  63.             .AddKeyWord "Error", "Error"
  64.             .AddKeyWord "New", "New"
  65.             .AddKeyWord "On", "On"
  66.             .AddKeyWord "Is", "Is"
  67.             .AddKeyWord "Nothing", "Nothing"
  68.             .AddKeyWord "True", "True"
  69.             .AddKeyWord "False", "False"
  70.             .AddKeyWord "Define Directive", "#define"
  71.             .AddKeyWord "#if", "#if"
  72.             .AddKeyWord "type", "type"
  73.             .AddKeyWord "Const", "Const"
  74.             .AddKeyWord "Enum", "Enum"
  75.             .AddKeyWord "Sub", "Sub"
  76.             .AddKeyWord "Let", "Let"
  77.             .AddKeyWord "Optional", "Optional"
  78.             .AddKeyWord "Set", "Set"
  79.             .AddKeyWord "Get", "Get"
  80.             .AddKeyWord "Or", "Or"
  81.             .AddKeyWord "And", "And"
  82.             .AddKeyWord "Function", "Function"
  83.             .AddKeyWord "Select", "Select"
  84.             .AddKeyWord "Case", "Case"
  85.             .AddKeyWord "LBound", "LBound"
  86.             .AddKeyWord "UBound", "UBound"
  87.             .AddKeyWord "Boolean", "Boolean"
  88.             .AddKeyWord "ByVal", "ByVal"
  89.             .AddKeyWord "ByRef", "ByRef"
  90.             .AddKeyWord "End", "End"
  91.             .AddKeyWord "DConst", "#const"
  92.             .AddKeyWord "Variable Const", "VConst"
  93.             .AddKeyWord "Do", "Do"
  94.             .AddKeyWord "Dimention Variable", "Dim"
  95.             .AddKeyWord "With Block", "With"
  96.             .AddKeyWord "While", "While"
  97.             .AddKeyWord "Until", "Until"
  98.             .AddKeyWord "Loop", "Loop"
  99.             .AddKeyWord "WEnd", "WEnd"
  100.             .AddKeyWord "Declare", "Declare"
  101.             .AddKeyWord "To", "To"
  102.             .AddKeyWord "For", "For"
  103.             .AddKeyWord "Each", "Each"
  104.             .AddKeyWord "In", "In"
  105.             .AddKeyWord "Next", "Next"
  106.             .AddKeyWord "Step", "Step"
  107.             .AddKeyWord "Option", "Option"
  108.             .AddKeyWord "Explicit", "Explicit"
  109.             .AddKeyWord "Remainder", "Mod"
  110.             .AddKeyWord "Method Call", "Call"
  111.             .AddKeyWord "Convert To Integer", "CInt"
  112.             .AddKeyWord "Convert To Single", "CSng"
  113.             .AddKeyWord "Convert To Long", "CLng"
  114.             .AddKeyWord "Convert To Byte", "CByt"
  115.             .AddKeyWord "Convert To Double", "CDbl"
  116.             .AddKeyWord "Private Declarator", "Private"
  117.             .AddKeyWord "Public Declarator", "Public"
  118.             .AddKeyWord "WithEvents", "WithEvents"
  119.             .AddKeyWord "Property", "Property"
  120.             .AddKeyWord "Long data type", "Long"
  121.             .AddKeyWord "Integer data type", "Integer"
  122.             .AddKeyWord "Byte data type", "Byte"
  123.             .AddKeyWord "String data type", "String"
  124.             .AddKeyWord "Double data type", "Double"
  125.             .AddKeyWord "Library", "Lib"
  126.             .AddKeyWord "Define 'As' Type", "As"
  127.             .AddOperator "Group Selective Bracket - Left", "(", 0
  128.             .AddOperator "Group Selective Bracket - Right", ")", 0
  129.             .AddOperator "Word Selective Bracket - Left", "[", 0
  130.             .AddOperator "Word Selective Bracket - Right", "]", 0
  131.             .AddOperator "Colon", ":"
  132.             .AddOperator "Plus", "+", 3
  133.             .AddOperator "Minus", "-", 3
  134.             .AddOperator "Percent", "%", 3
  135.             .AddOperator "Minus", "*", 2
  136.             .AddOperator "Division", "/", 2
  137.             .AddOperator "Integer Division", "\", 2
  138.             .AddOperator "Also", "&", 4
  139.             .AddOperator "Object.Property Seperator", "."
  140.             .AddOperator "Item List (Seperator, Item)", ","
  141.             .AddOperator "Object!Property Get/Let/Set Seperator", "!"
  142.             .AddOperator "Greater Than", ">", 5
  143.             .AddOperator "Less Than", "<", 5
  144.             .AddOperator "Equals", "=", 5
  145.             .AddOperator ">=", ">=", 5
  146.             .AddOperator "<=", "<=", 5
  147.             .AddOperator "=>", "=>", 5
  148.             .AddOperator "=<", "=<", 5
  149.             .AddOperator "Power Of", "^", 1
  150.             .AddOperator "Number", "#"
  151.             .AddOperator "_", "_"
  152.         End With
  153.     End If
  154.     FixLanguage
  155. End Property
  156.  
  157. Public Property Get Language() As SCLanguage
  158. Attribute Language.VB_Description = "Reference to the language"
  159.     Set Language = r_gslLanguage
  160. End Property
  161.  
  162. Public Property Set Language(ByVal v_gslLanguage As SCLanguage)
  163.     Set r_gslLanguage = v_gslLanguage
  164. End Property
  165.  
  166. Friend Function LexicalParse(ByVal Expression As String) As LexicalResult
  167. Attribute LexicalParse.VB_Description = "Parses text into a token result"
  168.     Dim m_lngPosition As Long
  169.     Dim m_glpProcess As LexicalProcess
  170.     Dim m_lprResult As LexicalProcResult
  171.     Dim m_glrResult As LexicalResult
  172.     m_glpProcess.Expression = Expression
  173.     m_glpProcess.ExpressionLength = Len(Expression)
  174.     m_lngPosition = 1
  175.     m_glpProcess.CharIndex = 1
  176.     Do
  177.         m_glpProcess.Position = m_lngPosition
  178.         With m_lprResult
  179.             m_lprResult = LexicalKeyWord(m_glpProcess)
  180.             If Not .Success Then _
  181.                 m_lprResult = LexicalConstant(m_glpProcess)
  182.             If Not .Success Then _
  183.                 m_lprResult = LexicalIdentifier(m_glpProcess)
  184.             If Not .Success Then _
  185.                 m_lprResult = LexicalOperator(m_glpProcess)
  186.             If Not .Success Then _
  187.                 m_lprResult = LexicalString(m_glpProcess)
  188.             If Not .Success Then _
  189.                 m_lprResult = LexicalComment(m_glpProcess)
  190.             If Not .Success Then _
  191.                 m_lprResult = LexicalWhiteSpace(m_glpProcess)
  192.             If Not .Success Then
  193.                 m_lngPosition = m_lngPosition + 1
  194.                     '//This should NEVER happen.
  195.             ElseIf .Success Then
  196.                 AddToken m_lprResult.Token, m_glrResult.Tokens
  197.                 m_lngPosition = .NewPosition
  198.             End If
  199.         End With
  200.         'Form1.ProgressUpdate m_glpProcess.Position, m_glpProcess.ExpressionLength
  201.     Loop Until m_lngPosition > Len(Expression)
  202.     'Form1.ProgressUpdate m_glpProcess.ExpressionLength, m_glpProcess.ExpressionLength
  203.     LexicalParse = m_glrResult
  204. End Function
  205.  
  206. Friend Function SemanticParse(LexicalInput As LexicalResult) As SemanticResult
  207.     
  208. End Function
  209.  
  210. Friend Function StandardParse(ByVal Expression As String) As SemanticResult
  211.     StandardParse = SemanticParse(LexicalParse(Expression))
  212. End Function
  213.  
  214. Private Function LexicalString(Process As LexicalProcess) As LexicalProcResult
  215. Declarations:
  216.     Dim m_lngPosition As Long
  217.     Dim m_strChar As String * 1
  218.     Dim m_lprResult As LexicalProcResult
  219.  
  220.     Dim m_booFoundQuote As Boolean
  221.     Dim m_chiInfo As CharInfo
  222. Try:
  223.     On Error GoTo Catch
  224.     m_lngPosition = Process.Position
  225.     Do
  226.         m_strChar = Mid$(Process.Expression, m_lngPosition, 1)
  227.         m_chiInfo = GetCharInfo(m_strChar)
  228.         If Process.CharIndex = 1 Then
  229.             If Not m_strChar = m_gl_CST_strOprQuote Then
  230.                 GoTo Failure
  231.             End If
  232.         Else
  233.             If m_booFoundQuote Then
  234.                 If IsOperator(m_strChar, m_colOperators) Or m_strChar = vbCr Or m_strChar = vbLf Or m_strChar = m_gl_CST_strOprSpace Then
  235.                     Process.CharIndex = Process.CharIndex - 1
  236.                     GoTo Success
  237.                 ElseIf m_strChar = m_gl_CST_strOprQuote Then
  238.                     m_booFoundQuote = False
  239.                 Else
  240.                     GoTo Failure
  241.                 End If
  242.             ElseIf m_strChar = m_gl_CST_strOprQuote Then
  243.                 m_booFoundQuote = Not m_booFoundQuote
  244.                 If m_lngPosition = Process.ExpressionLength Then
  245.                     Process.CharIndex = Process.CharIndex + 1
  246.                     GoTo Success
  247.                 End If
  248.             End If
  249.         End If
  250.         Process.CharIndex = Process.CharIndex + 1
  251.         m_lngPosition = m_lngPosition + 1
  252.     Loop Until m_lngPosition > Process.ExpressionLength
  253. Finally:
  254.     GoTo EndTry
  255. Success:
  256.     With m_lprResult
  257.         .Success = True
  258.         With .Token
  259.             .TokenType = G_LTT_String
  260.             .Value = Mid$(Process.Expression, Process.Position, Process.CharIndex)
  261.             .Length = Len(.Value)
  262.         End With
  263.         .NewPosition = Process.Position + Process.CharIndex
  264.     End With
  265.     LexicalString = m_lprResult
  266.     GoTo EndTry
  267. Failure:
  268.     m_lprResult.Success = False
  269.     GoTo EndTry
  270. Catch:
  271.     m_lprResult.Success = False
  272.     GoTo EndTry
  273. EndTry:
  274.     Process.CharIndex = 1
  275.     Exit Function
  276. End Function
  277.  
  278. Private Function LexicalComment(Process As LexicalProcess) As LexicalProcResult
  279. Declarations:
  280.     Dim m_lngPosition As Long
  281.     Dim m_strChar As String * 1
  282.     Dim m_lprResult As LexicalProcResult
  283.  
  284.     Dim m_chiInfo As CharInfo
  285.     Dim m_lngNextItem As Long
  286.     Dim m_lngNextUnderItem As Long
  287.     Dim m_lngCRPos As Long
  288. Try:
  289.     On Error GoTo Catch
  290.     m_lngPosition = Process.Position
  291.     m_strChar = Mid$(Process.Expression, m_lngPosition, 1)
  292.     m_chiInfo = GetCharInfo(m_strChar)
  293.     If Process.CharIndex = 1 Then
  294.         If m_chiInfo.IsAlpha Or m_chiInfo.IsNumeric Then
  295.             GoTo Failure
  296.         ElseIf m_strChar = m_gl_CST_strOprApostrophe Then
  297.             GoTo Success
  298.         End If
  299.     End If
  300.     Process.CharIndex = Process.CharIndex + 1
  301. Finally:
  302.     GoTo EndTry
  303. Success:
  304.     With m_lprResult
  305.         m_lngNextItem = Process.Position
  306.         m_lngNextUnderItem = m_lngNextItem
  307.         m_lngCRPos = m_lngNextItem
  308.         Do
  309.             m_lngNextItem = NextCarrageReturn(Process.Expression, m_lngCRPos)
  310.             m_lngNextUnderItem = InStr(m_lngCRPos, Process.Expression, " _" & vbCr)
  311.             m_lngCRPos = m_lngNextItem + 1
  312.         Loop Until m_lngNextItem = 0 Or (m_lngNextUnderItem > m_lngNextItem) Or m_lngNextUnderItem = 0
  313.         If m_lngNextItem = 0 Then
  314.             Process.CharIndex = (Process.ExpressionLength - (Process.Position - 1))
  315.         Else
  316.             Process.CharIndex = ((m_lngNextItem - 1) - (Process.Position - 1))
  317.         End If
  318.         .Success = True
  319.         .NewPosition = Process.Position + Process.CharIndex
  320.         With .Token
  321.             .Value = Mid$(Process.Expression, Process.Position, Process.CharIndex)
  322.             .TokenType = G_LTT_Comment
  323.             .Length = Len(.Value)
  324.         End With
  325.     End With
  326.     LexicalComment = m_lprResult
  327.     GoTo EndTry
  328. Failure:
  329.     m_lprResult.Success = False
  330.     GoTo EndTry
  331. Catch:
  332.     m_lprResult.Success = False
  333.     GoTo EndTry
  334. EndTry:
  335.     Process.CharIndex = 1
  336.     Exit Function
  337. End Function
  338.  
  339. Private Function LexicalConstant(Process As LexicalProcess) As LexicalProcResult
  340. Declarations:
  341.     Dim m_lngPosition As Long
  342.     Dim m_strChar As String * 1
  343.     Dim m_lprResult As LexicalProcResult
  344.     Dim m_booAndLast As Boolean
  345.     Dim m_chiInfo As CharInfo
  346.     Dim m_booIsNegative As Boolean
  347.     Dim m_booIsHex As Boolean
  348. Try:
  349.     On Error GoTo Catch
  350.     m_lngPosition = Process.Position
  351.     Do
  352.         m_strChar = Mid$(Process.Expression, m_lngPosition, 1)
  353.         m_chiInfo = GetCharInfo(m_strChar)
  354.         If Process.CharIndex = 1 Then
  355.             If (m_strChar = m_gl_CST_strOprMinus Or m_strChar = m_gl_CST_strOprAnd) And Not Process.Position = Process.ExpressionLength Then
  356.                 If m_strChar = m_gl_CST_strOprMinus Then
  357.                     m_booIsNegative = True
  358.                 ElseIf m_strChar = m_gl_CST_strOprAnd Then
  359.                     m_booIsHex = True
  360.                 End If
  361.             ElseIf Not m_chiInfo.IsNumeric Then
  362.                 GoTo Failure
  363.             ElseIf m_lngPosition = Process.ExpressionLength Then
  364.                 Process.CharIndex = Process.CharIndex + 1
  365.                 GoTo Success
  366.             End If
  367.         Else
  368.             If Not m_booIsHex Then
  369.                 If m_booIsNegative Then
  370.                     If Not m_chiInfo.IsNumeric Then
  371.                         If Process.CharIndex = 2 Then
  372.                             m_booIsNegative = False
  373.                             GoTo Failure
  374.                         Else
  375.                             If m_strChar = vbCr Or m_strChar = vbLf Or m_strChar = m_gl_CST_strOprSpace Or IsOperator(m_strChar, m_colOperators) Or (m_lngPosition >= Process.ExpressionLength) Then
  376.                                 If m_strChar = m_gl_CST_strOprAnd Or m_strChar = m_gl_CST_strOprPercent Then
  377.                                     Process.CharIndex = Process.CharIndex + 1
  378.                                     m_booAndLast = True
  379.                                 End If
  380.                                 GoTo Success
  381.                             Else
  382.                                 GoTo Failure
  383.                             End If
  384.                         End If
  385.                     Else
  386.                         If m_lngPosition = Process.ExpressionLength Then
  387.                             Process.CharIndex = Process.CharIndex + 1
  388.                             GoTo Success
  389.                         End If
  390.                     End If
  391.                 Else
  392.                     If Not m_chiInfo.IsNumeric Then
  393.                         If m_strChar = vbCr Or m_strChar = vbLf Or m_strChar = m_gl_CST_strOprSpace Or IsOperator(m_strChar, m_colOperators) Then
  394.                             If m_strChar = m_gl_CST_strOprAnd Or m_strChar = m_gl_CST_strOprPercent Then
  395.                                 Process.CharIndex = Process.CharIndex + 1
  396.                                 m_booAndLast = True
  397.                             End If
  398.                             GoTo Success
  399.                         Else
  400.                             GoTo Failure
  401.                         End If
  402.                     End If
  403.                 End If
  404.             Else
  405.                 If Process.CharIndex = 2 Then
  406.                     If Not LCase$(m_strChar) = "h" Then
  407.                         GoTo Failure
  408.                     End If
  409.                 ElseIf Process.CharIndex = 3 Then
  410.                     Select Case LCase$(m_strChar)
  411.                         Case "0" To "9", "a" To "f"
  412.                         Case Else
  413.                             GoTo Failure
  414.                     End Select
  415.                 Else
  416.                     Select Case LCase$(m_strChar)
  417.                         Case "0" To "9", "a" To "f"
  418.                             If m_lngPosition = Process.ExpressionLength Then
  419.                                 Process.CharIndex = Process.CharIndex + 1
  420.                                 GoTo Success
  421.                             End If
  422.                         Case m_gl_CST_strOprAnd
  423.                             m_booAndLast = True
  424.                             Process.CharIndex = Process.CharIndex + 1
  425.                             GoTo Success
  426.                         Case Else
  427.                             If m_strChar = vbCr Or m_strChar = vbLf Or m_strChar = m_gl_CST_strOprSpace Or IsOperator(m_strChar, m_colOperators) Then
  428.                                 GoTo Success
  429.                             Else
  430.                                 GoTo Failure
  431.                             End If
  432.                     End Select
  433.                 End If
  434.             End If
  435.         End If
  436.         Process.CharIndex = Process.CharIndex + 1
  437.         m_lngPosition = m_lngPosition + 1
  438.     Loop Until m_lngPosition > Process.ExpressionLength
  439. Finally:
  440.     GoTo Success
  441. Success:
  442.     With m_lprResult
  443.         .Success = True
  444.         .NewPosition = Process.Position + Process.CharIndex - 1
  445.         With .Token
  446.             .Length = Process.CharIndex - 1
  447.             .Value = CLng(Mid$(Process.Expression, Process.Position, Process.CharIndex - 1 - IIf((m_booAndLast), 1, 0)))
  448.             .TokenType = G_LTT_Constant
  449.             .Position = Process.Position
  450.         End With
  451.     End With
  452.     LexicalConstant = m_lprResult
  453.     GoTo EndTry
  454. Failure:
  455.     m_lprResult.Success = False
  456.     GoTo EndTry
  457. Catch:
  458.     m_lprResult.Success = False
  459.     GoTo EndTry
  460. EndTry:
  461.     Process.CharIndex = 1
  462.     Exit Function
  463. End Function
  464.  
  465. Private Function LexicalWhiteSpace(Process As LexicalProcess) As LexicalProcResult
  466. Declarations:
  467.     Dim m_lngPosition As Long
  468.     Dim m_strChar As String * 1
  469.     Dim m_lprResult As LexicalProcResult
  470.  
  471.     Dim m_chiInfo As CharInfo
  472. Try:
  473.     On Error GoTo Catch
  474.     m_lngPosition = Process.Position
  475.     Do
  476.         m_strChar = Mid$(Process.Expression, m_lngPosition, 1)
  477.         m_chiInfo = GetCharInfo(m_strChar)
  478.         Select Case m_strChar
  479.             Case m_gl_CST_strOprSpace, vbTab, vbCr, vbLf
  480.                 If m_lngPosition = Process.ExpressionLength Then
  481.                     Process.CharIndex = Process.CharIndex + 1
  482.                     GoTo Success
  483.                 End If
  484.             Case Else
  485.                 If Process.CharIndex > 1 Then
  486.                     Process.CharIndex = Process.CharIndex - 1
  487.                     GoTo Success
  488.                 Else
  489.                     GoTo Failure
  490.                 End If
  491.         End Select
  492.         Process.CharIndex = Process.CharIndex + 1
  493.         m_lngPosition = m_lngPosition + 1
  494.     Loop Until m_lngPosition > Process.ExpressionLength
  495. Finally:
  496.     GoTo Success
  497. Success:
  498.     With m_lprResult
  499.         .Success = True
  500.         .NewPosition = Process.Position + Process.CharIndex
  501.         With .Token
  502.             .Value = Mid$(Process.Expression, Process.Position, Process.CharIndex)
  503.             .TokenType = G_LTT_WhiteSpace
  504.             .Length = Process.CharIndex
  505.             .Position = Process.Position
  506.         End With
  507.     End With
  508.     LexicalWhiteSpace = m_lprResult
  509.     GoTo EndTry
  510. Failure:
  511.     m_lprResult.Success = False
  512.     GoTo EndTry
  513. Catch:
  514.     m_lprResult.Success = False
  515.     GoTo EndTry
  516. EndTry:
  517.     Process.CharIndex = 1
  518.     Exit Function
  519. End Function
  520.  
  521. Private Function LexicalKeyWord(Process As LexicalProcess) As LexicalProcResult
  522. Declarations:
  523.     Dim m_lngPosition As Long
  524.     Dim m_strChar As String * 1
  525.     Dim m_lprResult As LexicalProcResult
  526.     Dim m_chiInfo As CharInfo
  527. Try:
  528.     On Error GoTo Catch
  529.     m_lngPosition = Process.Position
  530.     Do
  531.         m_strChar = Mid$(Process.Expression, m_lngPosition, 1)
  532.         m_chiInfo = GetCharInfo(m_strChar)
  533.         If Process.CharIndex = 1 Then
  534.             If (m_chiInfo.IsNumeric Or Not m_chiInfo.IsAlpha) And Not IsOperator(m_strChar, m_colOperators) Then
  535.                 GoTo Failure
  536.             End If
  537.         Else
  538.             Select Case True
  539.                 Case m_strChar = m_gl_CST_strOprUnderscore
  540.                     If m_lngPosition = Process.ExpressionLength Then
  541.                         Process.CharIndex = Process.CharIndex + 1
  542.                         GoTo Success
  543.                     End If
  544.                 Case IsOperator(m_strChar, m_colOperators), m_strChar = m_gl_CST_strOprSpace, m_strChar = vbCr, m_strChar = vbLf, m_strChar = vbTab
  545.                     GoTo Success
  546.                 Case Else
  547.                     If m_lngPosition = Process.ExpressionLength Then
  548.                         Process.CharIndex = Process.CharIndex + 1
  549.                         GoTo Success
  550.                     End If
  551.             End Select
  552.         End If
  553.         Process.CharIndex = Process.CharIndex + 1
  554.         m_lngPosition = m_lngPosition + 1
  555.     Loop Until m_lngPosition > Process.ExpressionLength
  556. Finally:
  557.     GoTo EndTry
  558. Success:
  559.     With m_lprResult
  560.         .Success = True
  561.         .NewPosition = Process.Position + Process.CharIndex - 1
  562.         With .Token
  563.             .Value = Mid$(Process.Expression, Process.Position, Process.CharIndex - 1)
  564.             If Not IsKeyword(.Value, m_colKeyWords) Then
  565.                 GoTo Failure
  566.             End If
  567.             .Length = Len(.Value)
  568.             .TokenType = G_LTT_Keyword
  569.             .Position = Process.Position
  570.         End With
  571.     End With
  572.     LexicalKeyWord = m_lprResult
  573.     GoTo EndTry
  574. Failure:
  575.     m_lprResult.Success = False
  576.     GoTo EndTry
  577. Catch:
  578.     m_lprResult.Success = False
  579.     GoTo EndTry
  580. EndTry:
  581.     Process.CharIndex = 1
  582.     Exit Function
  583. End Function
  584.  
  585. Private Function LexicalOperator(Process As LexicalProcess) As LexicalProcResult
  586. Declarations:
  587.     Dim m_lngPosition As Long
  588.     Dim m_strChar As String * 1
  589.     Dim m_lprResult As LexicalProcResult
  590.     Dim m_strExp As String
  591.     Dim m_chiInfo As CharInfo
  592.     Dim m_lngSuccessChar As Long
  593. Try:
  594.     On Error GoTo Catch
  595.     m_lngPosition = Process.Position
  596.     Do
  597.         m_strChar = Mid$(Process.Expression, m_lngPosition, 1)
  598.         m_chiInfo = GetCharInfo(m_strChar)
  599.         m_strExp = m_strExp & m_strChar
  600.         If Process.CharIndex = 1 Then
  601.             If IsOperator(m_strChar, m_colOperators) Then
  602.                 m_lngSuccessChar = Process.CharIndex
  603.                 If Process.Position = Process.ExpressionLength Then
  604.                     Process.CharIndex = Process.CharIndex + 1
  605.                     GoTo Success
  606.                 End If
  607.             End If
  608.         Else
  609.             If Not IsOperator(m_strExp, m_colOperators) Then
  610.                 GoTo Success
  611.             Else
  612.                 m_lngSuccessChar = Process.CharIndex + 1
  613.                 If m_lngPosition = Process.ExpressionLength Then
  614.                     Process.CharIndex = Process.CharIndex + 1
  615.                     GoTo Success
  616.                 End If
  617.             End If
  618.         End If
  619.         Process.CharIndex = Process.CharIndex + 1
  620.         m_lngPosition = m_lngPosition + 1
  621.     Loop Until m_lngPosition > Process.ExpressionLength
  622. Finally:
  623.     GoTo EndTry
  624. Success:
  625.     With m_lprResult
  626.         .Success = True
  627.         .NewPosition = Process.Position + Process.CharIndex - 1
  628.         With .Token
  629.             .Length = Process.CharIndex - 1
  630.             .Position = Process.Position
  631.             .TokenType = G_LTT_Operator
  632.             .Value = Mid$(Process.Expression, Process.Position, Process.CharIndex - 1)
  633.             If Not IsOperator(.Value, m_colOperators) Then
  634.                 If m_lngSuccessChar = 0 Then
  635.                     GoTo Failure
  636.                 Else
  637.                     Process.CharIndex = m_lngSuccessChar
  638.                     GoTo Success
  639.                         '//update
  640.                 End If
  641.             End If
  642.         End With
  643.     End With
  644.     LexicalOperator = m_lprResult
  645.     GoTo EndTry
  646. Failure:
  647.     m_lprResult.Success = False
  648.     GoTo EndTry
  649. Catch:
  650.     m_lprResult.Success = False
  651.     GoTo EndTry
  652. EndTry:
  653.     Process.CharIndex = 1
  654.     Exit Function
  655. End Function
  656.  
  657. Private Function LexicalIdentifier(Process As LexicalProcess) As LexicalProcResult
  658. Declarations:
  659.     Dim m_lngPosition As Long
  660.     Dim m_strChar As String * 1
  661.     Dim m_lprResult As LexicalProcResult
  662.     Dim m_chiInfo As CharInfo
  663. Try:
  664.     On Error GoTo Catch
  665.     m_lngPosition = Process.Position
  666.     Do
  667.         m_strChar = Mid$(Process.Expression, m_lngPosition, 1)
  668.         m_chiInfo = GetCharInfo(m_strChar)
  669.         If Process.CharIndex = 1 Then
  670.             If m_chiInfo.IsNumeric Or Not m_chiInfo.IsAlpha Then
  671.                 GoTo Failure
  672.             ElseIf m_lngPosition = Process.ExpressionLength Then
  673.                 Process.CharIndex = Process.CharIndex + 1
  674.                 GoTo Success
  675.             End If
  676.         Else
  677.             Select Case True
  678.                 Case m_strChar = m_gl_CST_strOprUnderscore
  679.                     If m_lngPosition = Process.ExpressionLength Then
  680.                         Process.CharIndex = Process.CharIndex + 1
  681.                         GoTo Success
  682.                     End If
  683.                 Case IsOperator(m_strChar, m_colOperators), m_strChar = m_gl_CST_strOprSpace, m_strChar = vbCr, m_strChar = vbLf, m_strChar = vbTab
  684.                     GoTo Success
  685.                 Case Else
  686.                     If m_lngPosition = Process.ExpressionLength Then
  687.                         Process.CharIndex = Process.CharIndex + 1
  688.                         GoTo Success
  689.                     End If
  690.             End Select
  691.         End If
  692.         Process.CharIndex = Process.CharIndex + 1
  693.         m_lngPosition = m_lngPosition + 1
  694.     Loop Until m_lngPosition > Process.ExpressionLength
  695. Finally:
  696.     GoTo EndTry
  697. Success:
  698.     With m_lprResult
  699.         .Success = True
  700.         .NewPosition = Process.Position + Process.CharIndex - 1
  701.         With .Token
  702.             .Value = Mid$(Process.Expression, Process.Position, Process.CharIndex - 1)
  703.             .Length = Len(.Value)
  704.             .TokenType = G_LTT_Identifier
  705.             .Position = Process.Position
  706.         End With
  707.     End With
  708.     LexicalIdentifier = m_lprResult
  709.     GoTo EndTry
  710. Failure:
  711.     m_lprResult.Success = False
  712.     GoTo EndTry
  713. Catch:
  714.     m_lprResult.Success = False
  715.     GoTo EndTry
  716. EndTry:
  717.     Process.CharIndex = 1
  718.     Exit Function
  719. End Function
  720.  
  721. Private Sub AddToken(Token As LexicalToken, Tokens As LexicalTokens)
  722.     With Tokens
  723.         If .Count = 0 Then
  724.             ReDim .Tokens(1 To .Count + 1)
  725.         Else
  726.             ReDim Preserve .Tokens(1 To .Count + 1)
  727.         End If
  728.         .Count = .Count + 1
  729.         With .Tokens(.Count)
  730.             .CustID = Token.CustID
  731.             .Length = Token.Length
  732.             .Position = Token.Position
  733.             .TokenType = Token.TokenType
  734.             .Value = Token.Value
  735.         End With
  736.     End With
  737. End Sub
  738.  
  739. Public Sub FixLanguage()
  740. Attribute FixLanguage.VB_Description = "Stores Operators and Keywrods into collections"
  741.     Dim m_lngLoop As Long
  742.     Set m_colKeyWords = New Collection
  743.     Set m_colOperators = New Collection
  744.     For m_lngLoop = 1 To Language.KeywordList.Count
  745.         m_colKeyWords.Add Language.KeywordList.Keywords(m_lngLoop).StringValue, "k" & LCase$(Language.KeywordList.Keywords(m_lngLoop).StringValue)
  746.     Next
  747.     For m_lngLoop = 1 To Language.OperatorList.Count
  748.         m_colOperators.Add Language.OperatorList.Operators(m_lngLoop).Value, "o" & LCase$(Language.OperatorList.Operators(m_lngLoop).Value)
  749.     Next
  750.     'Debug.Print m_colKeyWords.Count; m_colOperators.Count
  751. End Sub
  752.  
  753. Public Property Get OperatorCol() As Collection
  754.     Set OperatorCol = m_colOperators
  755. End Property
  756.